package com.wsx.rpc.metrics.listener;

import com.codahale.metrics.ConsoleReporter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author wangshuaixin
 * @Title: com.wsx.rpc.metrics.listener.MetriceListener
 * @Description: 服务监听器，主要是执行服务初始化后要操作的内容
 * @date 2018/11/29
 */
@Component
public class MetriceListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private ConsoleReporter consoleReporter;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        //开始记录相关的统计值
        consoleReporter.start(1, TimeUnit.SECONDS);
    }
}
